﻿Public Partial Class CreateRole
    Inherits BaseUserControl

    Protected Sub btnCreateRole_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Dim roleName As String = txtRoleName.Text.Trim
        If roleName.Length = 0 Then
            Me.Prompt("Please eneter a valid role name!", UserControlPromptTypes.Error)
            Exit Sub
        End If

        Try
            If Roles.RoleExists(roleName) Then
                Me.Prompt("Role name already exists!", UserControlPromptTypes.Alert)
                Exit Sub
            End If

            Roles.CreateRole(roleName)
            Me.Prompt("Role: " & roleName & " created successfully!", UserControlPromptTypes.Successful)
            Me.NotifyUpdate(sender, e)
            txtRoleName.Text = ""

        Catch ex As Exception
            Me.RaiseError(ex)
        End Try

    End Sub

    Public Overrides Sub Rebind()
        txtRoleName.Text = ""
    End Sub

    Private Sub Page_OnUpdate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.OnUpdate
        Rebind()
    End Sub

End Class